#ifndef _XMLUTILS_H_
#define _XMLUTILS_H_

#include <list>
#include <string>
#include "tinyxml.h"

#pragma once

class ElementList
{
public:
    typedef TiXmlHandle                value_type;
    typedef std::list< value_type >    valRepo_t;
    typedef valRepo_t::iterator         iterator;
    typedef valRepo_t::const_iterator   const_iterator;

public:
    ElementList();
    explicit ElementList( TiXmlHandle const & handle );

    const_iterator begin() const {
        return m_elements.begin(); }

    iterator begin() {
        return m_elements.begin(); }

    const_iterator end() const {
        return m_elements.end(); }

    iterator end() {
        return m_elements.end(); }

    bool empty() const {
        return m_elements.empty(); }

    size_t size() const {
        return m_elements.size(); }

private:
    valRepo_t    m_elements;
};

class XmlOperator
{
public:
    static TiXmlDocument * loadXml( const char * fileName );
    static ElementList getChildElements( const TiXmlDocument * doc );
    static ElementList getChildElements( TiXmlHandle const & elem );
    static TiXmlHandle getFirstElement( const TiXmlDocument * doc );
    static TiXmlHandle getChildElement( const TiXmlDocument * doc,
                                        std::string const & tagName,
                                        int index = 0 );
    static TiXmlHandle getChildElement( TiXmlHandle const & elem,
                                        std::string const & tagName,
                                        int index = 0 );
    static std::string getElementTag( TiXmlHandle const & elem );
    static std::string getAttribute( TiXmlHandle const & elem,
                                     std::string const & name );
    static std::string getText( TiXmlHandle const & elem );
    static bool haveChildElems( TiXmlHandle const & elem );
    static bool isNullHandle( TiXmlHandle const & elem );
};

#endif // _XMLUTILS_H_

